<template>
    <el-card class="box-card">
        <el-col :span="16">
            <el-form :model="StockLocationForm" ref="StockLocationForm" :rules="rules">
            <el-form-item label="名称" prop="name">
                <el-input v-model="StockLocationForm.name"></el-input>
            </el-form-item>
            <el-form-item label="地址" prop="origin">
                <el-input v-model="StockLocationForm.origin"></el-input>
            </el-form-item>
            <el-form-item label="所在城市名" prop="city_name">
                <el-input v-model="StockLocationForm.city_name"></el-input>
            </el-form-item>
            <el-form-item label="每公斤运费（元）" prop="weights">
                <el-input type="number" v-model.number="StockLocationForm.weights"></el-input>
            </el-form-item>
        </el-form>
        </el-col>
        <el-col :span="24" class="toolPage">
            <el-button type="primary" @click="submitForm('StockLocationForm')">更新配销中心</el-button>
            <el-button @click="returnStockLocationList" style="float: right">返回</el-button>
        </el-col>
    </el-card>
</template>
<script>
    export default {
        data() {
            return {
                StockLocationForm: {
                    name: '',
                    origin: '',
                    city_name: '',
                    weights: ''
                },
                rules: {
                    name: [
                        { required: true, message: '请输入名称', trigger: 'change blur' }
                    ],
                    origin: [
                        { required: true, message: '请输入地址', trigger: 'change blur' }
                    ],
                    city_name: [
                        { required: true, message: '请输入城市名', trigger: 'change blur' }
                    ],
                    weights: [
                        { required: true, message: '请输入每公斤运费（元）', }
                    ]
                }
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        alert('submit!');
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            returnStockLocationList() {
                this.$router.push(`/stock_locations`);
            }
        }

    }
</script>
